var adList = ["images/ad1.png","images/ad2.png","images/ad3.png","images/ad4.png"];
var curAdId = 0;
var epgTimer = null;
function showEpgBox(data){ 
	if(!data)return ;
	if(epgTimer){clearTimeout(epgTimer);epgTimer = null;}
	var img = $.getImageUrl('../'+data.icon,'../images/tv_default.png');
	var iconBox = document.getElementById('iconBox');
	iconBox.innerHTML = '<img src="'+img+'"/>';
	
	var epgBoxMidTitle = document.getElementById('epgBoxMidTitle');
	epgBoxMidTitle.innerHTML = data.name;
	
	var epgBoxList = document.getElementById('epgBoxList');
	var epgContent = '';
	var programList = getSession('p_'+data.id);  
	if(programList){
		try{
			eval("var propMap = "+programList); 
			var pList = propMap.propMap.program; 
			var con = '';
			for(var i = 0;i<pList.length;i++){ if(i>=3)break;
				var program = pList[i];
				con += '<div class="epgItem">';
					con += '<div class="epgDot"><img src="images/tvepg_dots.png"/></div>';
					con += '<div class="epgTime">'+formatEpgItem(program.beginTime)+'-'+formatEpgItem(program.endTime)+'</div>';
					con += '<div class="epgName">'+program.name+'</div>';
				con += '</div>';
			}
			epgContent = con;
		}catch(e){
			alert(e);
		}
	}
	if(!epgContent){
		
	}
	epgBoxList.innerHTML = epgContent;
	
	var epgAdBox = document.getElementById('epgAdBox');
	var ad = '';
	if(data.propMap && data.propMap.ads && data.propMap.ads.length > 0){
		var id = getRandomId(data.propMap.ads.length);
		
		ad = '<img src="'+$.getImageUrl(data.propMap.ads[id -1].imageUrl,'../images/icon.png')+'"/>';
	}
	epgAdBox.innerHTML = ad;
	var epgBox = document.getElementById('epgBox');
	epgBox.style.display = 'block';
	document.refresh();
}

function hideEpgBox(){
	epgTimer = setTimeout("hideEpgBoxAuto()",3000);
}

function hideEpgBoxAuto(){
	var epgBox = document.getElementById('epgBox');
	epgBox.style.display = 'none';
}


function formatEpgItem(time){
	var reCat = /\d{1,2}:\d{1,2}/i;
	var t = reCat.exec(time);
	return t;
	
}

function getRandomId(n){
	return parseInt(Math.random()*(n)+1);
}